package com.yxqz.manage_cms.controller;

import com.xuecheng.api.cms.CmsPageControllerApi;
import com.xuecheng.framework.domain.cms.CmsPage;
import com.xuecheng.framework.domain.cms.request.QueryPageRequest;
import com.xuecheng.framework.domain.cms.response.CmsPageResult;
import com.xuecheng.framework.model.response.CommonCode;
import com.xuecheng.framework.model.response.QueryResponseResult;
import com.xuecheng.framework.model.response.QueryResult;
import com.xuecheng.framework.model.response.ResponseResult;
import com.yxqz.manage_cms.service.CmsPageService;
import jdk.nashorn.internal.objects.annotations.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;


/**
 * 页面查询接口实现类
 */
@RestController
@RequestMapping("/cms/page")
public class CmsPageController implements CmsPageControllerApi {

    @Autowired
    CmsPageService cmsPageService;

    @Override
    @GetMapping("/list/{page}/{size}")
    public QueryResponseResult cmsPageFindList(@PathVariable("page") int page, @PathVariable("size") int size, QueryPageRequest queryPageRequest) {
        /** 测试浏览器url用的假数据
         *  QueryResult<CmsPage> queryResult = new QueryResult<CmsPage> ();
         *         ArrayList<CmsPage> list = new ArrayList<>();
         *         CmsPage cmsPage = new CmsPage();
         *         cmsPage.setPageName("测试哦");
         *         list.add(cmsPage);
         *         queryResult.setList(list);
         *         queryResult.setTotal(10);
         *         QueryResponseResult responseResult = new QueryResponseResult(CommonCode.SUCCESS,queryResult);
         *         return responseResult;
         */
        return cmsPageService.cmsPageFindList(page, size, queryPageRequest);
    }

    @Override
    @PostMapping("/add")
    public CmsPageResult cmsPageAdd(@RequestBody CmsPage cmsPage) {
        return cmsPageService.cmsPageAdd(cmsPage);
    }

    @Override
    @GetMapping("/get/{id}")
    public CmsPage findCmsPageById(@PathVariable("id") String pageId) {
        return cmsPageService.findCmsPageById(pageId);
    }

    @Override
    @PutMapping("/edit/{id}")
    public CmsPageResult editPage(@PathVariable("id") String pageId, @RequestBody CmsPage cmsPage) {
        return cmsPageService.editPage(pageId, cmsPage);
    }

    @Override
    @DeleteMapping("/del/{id}")
    public ResponseResult delPage(@PathVariable("id") String pageId) {
        return cmsPageService.delPage(pageId);
    }


    @PostMapping("/postPage/{pageId}")
    public ResponseResult postPage(@PathVariable("pageId") String pageId) {
        return cmsPageService.postPage(pageId);
    }
}
